/**
 * (C) 2007 - Boston University
 * 	Contact: Michael Ocean 

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
package step;

import java.util.ArrayList;

import step.exceptions.IllegalChildException;
import step.exceptions.STEPException;

public abstract class AbstractRead extends Node{
	
	protected ReadMode readmode;
	
	public AbstractRead(String id, ReadMode _readmode){
		super(id);
		readmode = _readmode;
    }

	public AbstractRead(ReadMode _readmode) {
		super();
		readmode = _readmode;
	}
	
	public enum ReadMode{ 
		BLOCK, NONBLOCK, NEXT, FIFO, LIFO, FIFOB, LIFOB;
		
		public static ReadMode parse(String s){
			if(s.equalsIgnoreCase("BLOCK"))
				return BLOCK;
			if(s.equalsIgnoreCase("NONBLOCK"))
				return NONBLOCK;
			if(s.equalsIgnoreCase("NEXT"))
				return NEXT;
			if(s.equalsIgnoreCase("FIFO"))
				return FIFO;
			if(s.equalsIgnoreCase("FIFOB"))
				return FIFOB;			
			if(s.equalsIgnoreCase("LIFO"))
				return LIFO;
			if(s.equalsIgnoreCase("LIFOB"))
				return LIFOB;
			throw new ArrayIndexOutOfBoundsException();
		}
	}
	
    protected void SetWanted(boolean v) throws EvaluationFailure { 
	    /* override to block/alter propegation */
	    rt_wanted = v;
    }
    
	@Override
	public void validate(Graph g, ArrayList<STEPException> compilationErrors) {
		if(this.children.length==1)
			if(this.children[0] instanceof AbstractTrigger)
				return;
		
		compilationErrors.add(new IllegalChildException(
				"Read node with ID = " + ID
						+ " Doesn't must have exactly one child of type Trigger "));
		
	}
}
